package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mobile/setmeal")
@Slf4j
public class SetmealController {
  @DubboReference
  private SetmealService setmealService;

  /**
   * @Author: JASON
   * @Date: 20:16 2021/1/9
   * @Parms []
   * @ReturnType: com.itheima.health.entity.Result
   * @Description: 查询所有
  */
  @RequestMapping("/getSetmeal")
  public Result getSetmeal(){
      //rpc调用查询所有套餐
      List<Setmeal> setmeals = setmealService.findAll();
      log.info("查询所有套餐"+setmeals);
      return new Result(true, MessageConst.GET_SETMEAL_LIST_SUCCESS,setmeals);
  }

  /**
   * @Author: JASON
   * @Date: 20:17 2021/1/9
   * @Parms [id]
   * @ReturnType: com.itheima.health.entity.Result
   * @Description: 根据id查找套餐
  */

    @RequestMapping("/findById")
    public Result findById(int id){
        //rpc调用查询数据
        Setmeal setmeal = setmealService.findById(id);
        //返回
        log.info("返回的setmeal"+setmeal);
        return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}